<?php
namespace Admin\Controller;
use Think\Controller;

class TestController extends CommonController
{
    public function show()
    {
        $web_close = M('sys_config')->where('cfg_name="web_close"')->field('cfg_value')->find();
        var_dump($web_close);exit;
    }
    //批量写入测试数据
    public function add()
    {
      if ($_GET) {
        $table = I('get.t');
        $v = I('get.v');
        $n = I('get.n');
      } else {
        $v = 0;
        $n = 50;
      }

      $sql = 'INSERT INTO '.$table.' VALUES';

    for ($i=0; $i < $n; $i++) {
      $data_1 = getRandStr(10);
      $data_2 = getRandStr(20);
      $sql .= ' (NULL, "'.$data_1.'", "'.$data_2.'"), ';
    }
    $sql = chop($sql, ', ');
    
    if ($v == 1) {
      echo $sql;
    } else {
      $truncate = 'truncate table '.$table;

      M()->execute($truncate);

      $res = M()->execute($sql);

      echo '已在 '.$table.' 数据库重新建立 '.$res.' 条测试数据';
    }
    }
}